﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;

public partial class Pages_Dashboard_Account_Track : System.Web.UI.Page, ICrumbedPage
{
	public int AccountID
	{
		get
		{
			int temp;
			int.TryParse(Request["ID"], out temp);
			return temp;
		}
	}
	protected BO.User User;
	private void Authenicate()
	{
		if (Authentication.IsCurrentUserAuthenticated())
			User = Authentication.GetCurrentUser();

		if (User == null)
			Response.Redirect("/default.aspx");
	}

    protected void Page_Load(object sender, EventArgs e)
    {
		Authenicate();
		if (!IsPostBack)
			LoadData();
    }

	private void LoadData()
	{
        tbTracedName.Text = string.Empty;
		var trackedPages = Logic.BusinessLogic.Stats.GetTrackedPages(AccountID);
		repTracks.DataSource = trackedPages;
		repTracks.DataBind();

        ucAccountSideMenu.AccountID = AccountID;

	}
	
	
	protected void tbnFb_Click(object sender, EventArgs e)
	{
        if (string.IsNullOrEmpty(tbTracedName.Text))
			return;
		Logic.BusinessLogic.Stats.CrateNewTrace(AccountID, BO.TracedAccount.AccountTypes.Facebook, tbTracedName.Text);
		
		LoadData();

	}

	protected void btnTwitter_Click(object sender, EventArgs e)
	{
        if (string.IsNullOrEmpty(tbTracedName.Text))
            return;
		Logic.BusinessLogic.Stats.CrateNewTrace(AccountID, BO.TracedAccount.AccountTypes.Twitter, tbTracedName.Text);
		
		LoadData();
	}

	private long? ConvertToNullableLong(string str)
	{
		try
		{
			return long.Parse(str);
		}
		catch (Exception)
		{
			return null;
		}
	}



    #region ICrumbedPage Members

    public int Level
    {
        get { return 4; }
    }

    public string TailName 
    {
        get { return "Track the competitors"; } 
    }


    #endregion
}